<div id="main_content">
    <h3><?php echo $title; ?></h3>
    <form id="searchEmployee" action="" method="POST">
    <div class="table_list searchemployee">
        <table width="100%" class="list_view_data" border="0" cellspacing="0" cellpadding="0">
            <tr align="center">
                <th><?php echo $this->lang->line('LR_Order'); ?></th>
                <th><?php echo $this->lang->line('LR_Fullname'); ?></th>
                <th><?php echo $this->lang->line('LR_Dateofbirth'); ?></th>
                <th><?php echo $this->lang->line('LR_IDCardNo'); ?></th>
                <th><?php echo $this->lang->line('LR_Email'); ?></th>
                <th><?php echo $this->lang->line('LR_Select'); ?></th>
            </tr>
            <?php
                if (count($data)){
                foreach ($data as $row){
            ?>
                <tr id="<?php echo $row['EmployeeId'];?>">
                    <td><?php echo ++$order; ?></td>
                    <td class="table_col"><?php echo dQuotes(subString($row['EmployeeName']));?></td>
                    <td class="table_col"><?php echo date('Y/m/d',strtotime($row['DateOfBirth'])); ?></td>
                    <td class="table_col"><?php echo $row['IdCardNumber']; ?></td>
                    <td class="table_col"><?php echo dQuotes(subString($row['Email'])); ?></td>
                    <?php
                    if(isset($employeeId)&&$row['EmployeeId']==$employeeId){
                    ?>
                    <td><input type="radio" name="CheckValue" id="<?php echo $row['EmployeeId'];?>" checked="checked" /></td>
                    <?php
                    }
                    else{
                    ?>
                       <td><input type="radio" name="CheckValue" id="<?php echo $row['EmployeeId'];?>" /></td> 
                    <?php
                    }
                    ?>
                </tr>
            <?php 
                }
            ?>
        </table>
        <div class="h_pagination" style="margin-top:10px;">
            <?php echo $pagi;  ?>
        </div> 
        <div class="choseButton" style="clear:both;">
            <input type="button" id="ok" value="<?php echo $this->lang->line('LR_ok'); ?>">
            <input type="button" id="cancel" value="<?php echo $this->lang->line('LR_cancel'); ?>">            
        </div>
        <?php 
        } 
        else{
        ?>
        </table>
        <p>
            <?php echo $this->lang->line('LR_null'); ?>
        </p>          
        <?php } ?>
    </div>
        <input type="hidden" name="hidEmployeeId" value="<?php if(isset($employeeId)&&$employeeId){ echo $employeeId;} ?>" id="hidEmployee" />
        <input type="hidden" name="hidLeaveId" value="<?php if(isset($leaveID)&&$leaveID){echo $leaveID;} ?>" id="hidLeaveId" />
        <input type="hidden" name="hidSegment" value="<?php if(isset($segment)&&$segment){echo $segment;} ?>" id="hidSegment" />
        
        <input type="hidden" name="txtStartDate" value="<?php if($this->session->userdata('txtStartDate')){ echo $this->session->userdata('txtStartDate'); } ?>" />
        <input type="hidden" name="txtEndDate" value="<?php if($this->session->userdata('txtEndDate')){ echo $this->session->userdata('txtEndDate'); } ?>" />
        <input type="hidden" name="txtStartTime" value="<?php if($this->session->userdata('txtStartTime')){ echo $this->session->userdata('txtStartTime'); } ?>" />
        <input type="hidden" name="txtEndTime" value="<?php if($this->session->userdata('txtEndTime')){ echo $this->session->userdata('txtEndTime'); } ?>" />
        <input type="hidden" name="cboLeavetype" value="<?php if($this->session->userdata('cboLeavetype')){ echo $this->session->userdata('cboLeavetype'); } ?>" />            
        
        <input type="hidden" name="hidDel" value="" id="hidSegment" />
    </form>
</div>
<script>
    // segment edit or add
    var segment = $("#hidSegment").val();
    // employee id
    var idEmployid = $("#hidEmployeeId").val();
    // leave id
    var leaveid = $("#hidLeaveId").val();
    $(document).ready(function(){
        // submit data when click pagination
        $('.paging li a').click(function(e) {
            e.preventDefault();
            var url = $(this).attr('href');
            if (url != 'javascript:void(0)') {
                $('#searchEmployee').attr('action', url);
                $('#searchEmployee').submit();
            }
        });        
        //click cancel
       $("#cancel").click(function(){
           if(segment=='null'){
               window.location.href = '<?php echo base_url('/leaveregistration'); ?>';
           }
           else{
             // segment  = edit
             if(segment=='edit'){
                 // leaveid != null && idEmployid!=null
                 if(leaveid!='null'&&idEmployid!='null'){
                    var url = '<?php echo base_url()."leaveregistration/edit"; ?>';
                    $('#searchEmployee').attr('action', url);
                    $('#searchEmployee').submit();
                 }
                 else{
                     window.location.href = '<?php echo base_url('/leaveregistration'); ?>';
                 }
             }
             // segment  = add
             if(segment=='add'){
                 // idEmployid!=null
                 if(idEmployid!='null'){
                    var url = '<?php echo base_url()."leaveregistration/add"; ?>';
                    $('#searchEmployee').attr('action', url);
                    $('#searchEmployee').submit();
                 }
                 else{
                     window.location.href = '<?php echo base_url('/leaveregistration/add'); ?>';
                 }                
             }
           }
       });
       // click ok
       $("#ok").click(function(){
          // segment null
           if(segment=='null'){
               window.location.href = '<?php echo base_url('/leaveregistration'); ?>';
           }
           // segment !=null
           else{
                // segment == edit
                if(segment=='edit'){
                    // leaveid!='null'
                    if(leaveid!='null'){
                        var valueID = $("input[type=radio]:checked").attr('id');
                        $('#hidEmployee').val(valueID);
                        if(!isNaN(valueID)){
                            var url = '<?php echo base_url()."leaveregistration/edit"; ?>';
                            $('#searchEmployee').attr('action', url);
                            $('#searchEmployee').submit();
                        }
                        else{
                            window.location.href = '<?php echo base_url('/leaveregistration'); ?>';
                        }
                    }
                    else{
                        window.location.href = '<?php echo base_url('/leaveregistration'); ?>';
                    }                    
                }
                // segment  = add
                if(segment=='add'){
                    var valueID = $("input[type=radio]:checked").attr('id');
                    $('#hidEmployee').val(valueID);
                    if(!isNaN(valueID)){
                        var url = '<?php echo base_url()."leaveregistration/add"; ?>';
                        $('#searchEmployee').attr('action', url);
                        $('#searchEmployee').submit();
                    }
                    else{
                        window.location.href = '<?php echo base_url('/leaveregistration/add'); ?>';
                    }
                }
           }
       });
    });
</script>